using MediatR;
using Microsoft.AspNetCore.Mvc;
using ProduceBasicData.Api.Application.Command.WarehouseManage;
using ProduceBasicData.Api.DTO.WarehouseDto;
using ProduceBasicData.ErrorCode;
using Swashbuckle.AspNetCore.Annotations;

namespace ProduceBasicData.Api.Controllers.WarehouseManage
{
    /// <summary>
    /// 入库单控制器
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class StockInOrderController : ControllerBase
    {
        private readonly IMediator _mediator;
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="mediator"></param>
        public StockInOrderController(IMediator mediator)
        {
            _mediator = mediator;
        }
        /// <summary>
        /// 创建入库单
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<int>> CreateStockInOrder(CreateStockInOrderCommand command)
        {
            return await _mediator.Send(command);
        }
        /// <summary>
        /// 获取入库单列表
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ApiResult<StockInOrderDto>> GetStockInOrderList([FromQuery] GetStockInOrderCommand command)
        {
            return await _mediator.Send(command);
        }
        /// <summary>
        /// 更新入库单
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<ApiResult<int>> UpdateStockInOrder(UpdateStockInOrderCommand command)
        {
            return await _mediator.Send(command);
        }
        /// <summary>
        /// 删除入库单
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<ApiResult<int>> DeleteStockInOrder(DeleteStockInOrderCommand command)
        {
            return await _mediator.Send(command);
        }
        /// <summary>
        /// 入库单批量删除
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<ApiResult<int>> DeleteRangeStockInOrder(DeleteRangeStockInOrderCommand command)
        {
            return await _mediator.Send(command);
        }

        /// <summary>
        /// 执行入库操作
        /// </summary>
        /// <param name="command">入库命令</param>
        /// <returns>操作结果</returns>
        [HttpPut]
        public async Task<ApiResult<int>> InWarehouse(InWarehouseCommand command)
        {
            return await _mediator.Send(command);
        }

        /// <summary>
        /// 获取单个入库单明细列表
        /// </summary>
        /// <param name="command">入库单ID</param>
        /// <returns>入库单明细列表</returns>
        [HttpGet]
        public async Task<ApiResult<List<StockInOrderItemDto>>> GetStockInOrderById([FromQuery]GetStockInOrderByIdCommand command)
        {
            return await _mediator.Send(command);
        }
    }
}